@app.route('/set_exam_time/<username>', methods=['GET', 'POST'])
def set_exam_time(username):
    if request.method == 'POST':
        class_name = request.form.get('class_name', '')
        exam_duration = request.form.get('exam_duration', '')
        if not class_name or not exam_duration:
            print("班级名称或考试时长缺失")  # 调试输出
            return "班级名称和考试时长不能为空", 400  # Bad request

        # 设置考试时间的逻辑
        end_time = datetime.now() + timedelta(minutes=int(exam_duration))
        exams[class_name] = {
            'start_time': datetime.now(),
            'end_time': end_time
        }
        session['exam'] = exams[class_name]

        print("考试时间设置成功，准备跳转")  # 调试输出

        # 设置考试时间后重定向到班级管理页面或其他页面
        return redirect(url_for('class_management', class_name=class_name))

    return render_template('set_exam_time.html', username=username)